#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'多继承'

__author__ = '许文杰'

from enum import Enum, unique
import logging
# logging的好处，它允许你指定记录信息的级别，有debug，info，warning，error等几个级别
# 当我们指定level=INFO时，logging.debug就不起作用了。同理，指定level=WARNING后，debug和info就不起作用了
logging.basicConfig(level=logging.INFO)

# 枚举
Weekday = Enum('Weekday', ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'))

class Week(Enum):
    Sun = 0  # Sun的value被设定为0, value默认是1
    Mon = 1
    Tue = 2
    Wed = 3
    Thu = 4
    Fri = 5
    Sat = 6

class Animal(object):
    def eat(self):
        print('eating')
class Mammal(Animal):
    def mammal(self):
        print('mammal')
class Bird(Animal):
    def downEgg(self):
        print('down egg')

class RunnableMixIn(object):
    def run(self):
        print('running')

class FlyableMixIn(object):
    def fly(self):
        print('flying')

# 狗继承哺乳动物类和会跑类，多继承
class Dog(Mammal, RunnableMixIn):
    pass

# 蝙蝠继承哺乳动画和会飞类，多继承
class Bat(Mammal, FlyableMixIn):
    pass

# 鸵鸟继承鸟类和会跑类，多继承
class Ostrich(Bird, RunnableMixIn):
    pass

# 鹦鹉继承鸟类和会飞类，多继承
class Parrot(Bird, FlyableMixIn):
    pass

def foo(s):
    assert s != 0, 'n is zero'
    return 10 / s
def bar(s):
    return foo(s) * 2



if __name__ == '__main__':

    dog = Dog()
    dog.eat()
    dog.mammal()
    dog.run()

    bat = Bat()
    bat.eat()
    bat.mammal()
    bat.fly()

    print(Weekday.Mon)
    for name, member in Weekday.__members__.items():
        print(name, '=>', member, ',', member.value)

    for name, member in Week.__members__.items():
        print(name, '=>', member, ',', member.value)

    # print(bar('2'))
    try:
        # print(bar('2'))
        print(bar(2))
    except Exception as e:
        logging.exception(e)
    finally:
        print('end')